package com.example.androiddemo01.views;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.androiddemo01.R;
import com.example.androiddemo01.bean.Student;
import com.example.androiddemo01.database.DBHelper;
import com.example.androiddemo01.utils.SpUtils;
import com.example.androiddemo01.widget.HeaderView;

public class ChangePasswordActivity extends AppCompatActivity implements View.OnClickListener {

   private HeaderView mHeaderView;
   private EditText mEtName;
   private EditText mEtCode;
   private EditText mEtClass;
   private EditText mEtUsername;
   private EditText mEtPassword;

   public Context mContext;

   private SpUtils mSpUtils;
   private EditText oldPasswordEditText, newPasswordEditText, confirmPasswordEditText;
   private Button changePasswordButton;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      mSpUtils = SpUtils.getInstance();
      setContentView(R.layout.activity_change_password);
      oldPasswordEditText = findViewById(R.id.old_password_edit_text);
      confirmPasswordEditText = findViewById(R.id.confirm_password_edit_text);
      changePasswordButton = findViewById(R.id.change_password_button);
      changePasswordButton.setOnClickListener(this);

   }


   @Override
   public void onClick(View v) {
      String confirmPassword = confirmPasswordEditText.getText().toString();
      Student student = new Student();
      student.setStudent_code(mSpUtils.getMap(SpUtils.LOGIN_KEY));
      student.setPassword(confirmPassword);
         DBHelper.getInstance(mContext).updatePassword(student);
         Toast.makeText(this, "密码已成功更改", Toast.LENGTH_SHORT).show();

   }
}
